﻿Imports KumaSystem.Activities.FileSystem
Imports NUnit.Framework
Imports Microsoft.Activities.UnitTesting

<TestFixture()>
Public Class TestFolderMove

    <SetUp()>
    Public Sub Setup()
        If Not IO.Directory.Exists("D:\ActivityTest") Then IO.Directory.CreateDirectory("D:\ActivityTest")
        For Each childFile In IO.Directory.GetFiles("D:\ActivityTest")
            My.Computer.FileSystem.DeleteFile(childFile)
        Next
        If Not IO.Directory.Exists("D:\ActivityTest\TestDestination") Then IO.Directory.CreateDirectory("D:\ActivityTest\TestDestination")
        For Each childFile In IO.Directory.GetFiles("D:\ActivityTest\TestDestination")
            My.Computer.FileSystem.DeleteFile(childFile)
        Next
        If Not IO.File.Exists("D:\ActivityTest\Test1.txt") Then
            My.Computer.FileSystem.WriteAllText("D:\ActivityTest\Test1.txt", "This is test strings", False)
        End If
        If Not IO.File.Exists("D:\ActivityTest\Test2.txt") Then
            My.Computer.FileSystem.WriteAllText("D:\ActivityTest\Test2.txt", "This is test strings2", False)
        End If
        If Not IO.File.Exists("D:\ActivityTest\TestDestination\Test1.txt") Then
            My.Computer.FileSystem.WriteAllText("D:\ActivityTest\TestDestination\Test1.txt", "This is test strings", False)
        End If
    End Sub

    <TearDown()>
    Public Sub TearDown()
        If IO.Directory.Exists("D:\ActivityTest\TestDestination2") Then My.Computer.FileSystem.DeleteDirectory("D:\ActivityTest\TestDestination2", FileIO.DeleteDirectoryOption.DeleteAllContents)
        If IO.Directory.Exists("D:\ActivityTest\TestDestination") Then My.Computer.FileSystem.DeleteDirectory("D:\ActivityTest\TestDestination", FileIO.DeleteDirectoryOption.DeleteAllContents)
        My.Computer.FileSystem.DeleteDirectory("D:\ActivityTest", FileIO.DeleteDirectoryOption.DeleteAllContents)
    End Sub

    <TestCase("D:\ActivityTest\TestDestination", "D:\ActivityTest\TestDestination2")>
    Public Sub MoveTestNormal(ByVal source As String, ByVal destination As String)

        Dim testActivity As New FolderMoveActivity With {
            .OriginalFolder = source, .TargetFolder = destination}
        Dim wfInvoker As New WorkflowInvokerTest(testActivity)
        wfInvoker.TestActivity()

        Assert.False(IO.Directory.Exists(source))
        Assert.True(IO.Directory.Exists(destination))
        Assert.True(IO.File.Exists(IO.Path.Combine(destination, "Test1.txt")))
        wfInvoker.AssertOutArgument.AreEqual("Result", True)

    End Sub

    <TestCase("D:\ActivityTest\TestDestination2", "D:\ActivityTest\TestDestination")>
    Public Sub MoveTestIllegal(ByVal source As String, ByVal destination As String)

        Dim testActivity As New FolderMoveActivity With {
            .OriginalFolder = source, .TargetFolder = destination}
        Dim wfInvoker As New WorkflowInvokerTest(testActivity)
        wfInvoker.TestActivity()

        Assert.False(IO.Directory.Exists(source))
        Assert.True(IO.Directory.Exists(destination))
        Assert.True(IO.File.Exists(IO.Path.Combine(destination, "Test1.txt")))
        wfInvoker.AssertOutArgument.AreEqual("Result", False)

    End Sub

End Class
